/*
 *  GeneticOptimizer.h
 *  Genetski
 *
 *  Created by Srđan Rašić on 11/17/11.
 *
 */

#pragma once
#include "Selection.h"
#include "CrossoverOperator.h"
#include "MutationOperator.h"
#include "Population.h"
#include "Chromosome.h"
#include "Function.h"

/** \mainpage notitle
 * \section intor01 Introduction
 * Demonstrates generic genetic algorithm for purposes of learning or writing solutions to simple problem.<br />
 * See Classes for more in-depth help.
 */

/**
 * Main class responsible for performing optimization.
 */
class GeneticOptimizer {
private:
	Function& _fun;
	Selection& _selOper;
	CrossoverOperator& _crossOper;
	MutationOperator& _mutatOper;

	Population* _population;

public:
	/**
	 * Initalizes minimizer by setting required operators and function which describes the problem.
	 * @param fun Function to optimize
	 * @param selOper Selection method
	 * @param crossOper Crossover operator
	 * @param mutatOper Mutation operator
	 */
	GeneticOptimizer(Function& fun, Selection& selOper, CrossoverOperator& crossOper, MutationOperator& mutatOper);

	/**
	 * Initializes minimizer. Must be called before optimization!
	 * @param numberOfIndividuals Number of chromosomes in population
	 * @param minimization True if minimization, False if should search for maximum
	 * @param precision To which decimal precision should search for solution
	 */
	void Initialize(int numberOfIndividuals, bool minimization, int precision);

	/**
	 * Returns best found solution of problem.
	 * @param numberOfIterations Number of iterations to perform
	 */
	std::vector<double> Optimize(unsigned int numberOfIterations);
};